package com.wfh.mianshiji.config;


import com.wfh.mianshiji.interceptor.InterviewHandshakeInterceptor;
import com.wfh.mianshiji.ws.InterviewWebSocketHandler;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * @author fenghuanwang
 */
@Configuration
@EnableWebSocket
@Slf4j
public class WebSocketConfig implements WebSocketConfigurer {

    @Resource
    private InterviewWebSocketHandler handler;

    @Resource
    private InterviewHandshakeInterceptor handshakeInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(handler, "/ws/interview")
                .addInterceptors(handshakeInterceptor)
                .setAllowedOrigins("*");
    }
}